<template>
    <div class="portlet box blue">
        <div class="portlet-title">
            <div class="caption">
                <i class="fa fa-gift"></i>门票查询</div>
            <div class="tools">
                <a href="javascript:;" class="collapse" data-original-title="" title=""></a>
            </div>
        </div>
        <div class="portlet-body form">
            <!-- BEGIN FORM-->
            <form action="#" class="form-horizontal">
                <div class="form-body">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">门票序列号</label>
                                <div class="col-md-9">
                                    <el-input placeholder="请输入您想查询的门票序列号" v-model="condition.TicketNo" clearable></el-input>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">门票类型</label>
                                <div class="col-md-9">
                                    <el-select v-model="condition.TicketTypes" multiple clearable placeholder="请选择门票类型" style="width:100%">
                                        <el-option v-for="item in words.prices" :key="item.PriceId" :label="item.PriceName" :value="item.PriceCode"></el-option>
                                    </el-select>                                  
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">通行证号</label>
                                <div class="col-md-9">
                                    <passport-select ref="passportSelect" @PassportSelectChanged="PassportSelectChanged"></passport-select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">创建日期</label>
                                <div class="col-md-9">
                                    <el-date-picker v-model="createTimeRange" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" :picker-options="pickerOptions" style="width:100%"></el-date-picker>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3">通行证状态</label>
                                <div class="col-md-9">
                                    <el-select v-model="condition.States" multiple placeholder="请选择通行证状态" style="width:100%">
                                        <el-option v-for="item in words.states" :key="item.value" :label="item.text" :value="item.value"></el-option>
                                    </el-select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="control-label col-md-3"></label>
                                <div class="col-md-9">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-actions">
                    <div class="row">
                        <div class="col-md-12 pull-right">
                            <div style="float:right;">
                                <button type="button" class="btn green" @click="exportTickets()">导出演出列表</button>
                                <button type="button" class="btn green" @click="query()">查询门票</button>
                                <button type="button" class="btn default" @click="clear()">清空条件</button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <!-- END FORM-->
        </div>
    </div>
</template>

<script>


import {GetPickerShortcuts} from 'web/utils.js';
import PassportSelect from 'components/passport_select.vue';

export default {
    props: {
        'data': {
            type: Object,
            default: null
        },
    },
    components: {
        PassportSelect
    },
    data() {
        return {
            condition: {
                States: [0, 1]
            },
            createTimeRange: null,
            words: {
                states: [
                    { text: '未激活', value:  0 },
                    { text: '已激活', value:  1 },
                    { text: '已删除', value: -1 }              
                ],
                prices: []
            },
            pickerOptions: GetPickerShortcuts(),
        }
    },
    watch: {
        'data': {
            handler: function(value){
                this.condition = value;
            },
            deep: true
        },
    },
    mounted() {

        // 加载门票类型
        this.$DataService.GetPricesByType('APHF|CONCERT')
            .then(ret => {
                this.words.prices = Object.values(ret);
            });

        this.query();
    },
    methods: {
        query() {
            // 将时间范围分解到condition中
            let _condition = Object.assign({}, this.condition);
            if (this.createTimeRange) {
                _condition.CreateTime0 = this.createTimeRange[0];
                _condition.CreateTime1 = this.createTimeRange[1];
            }
            this.$emit('GetTicketCondition', _condition);
        }, 

        PassportSelectChanged(userIds) {
            this.condition.UserIds = userIds;
        },

        clear() {
            this.condition = {
                States: [],
                TicketType: []
            };
            this.createTimeRange = null;
            this.$refs.passportSelect.clear();       
        },

        exportTickets() {
            this.query();            
            this.$TicketService.ExportTickets(this.condition);                
        }
    }
}
</script>

<style>

</style>
